package com.boatAnchorAssistant.service.controller.web;

import com.boatAnchorAssistant.pojo.param.tenant.*;
import com.boatAnchorAssistant.pojo.vo.tenant.*;
import com.boatAnchorAssistant.service.service.in.*;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import java.util.List;

/**
 *   web/企业
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 *
 */
@RestController
@RequestMapping("/tenant/web")
public class TenantWebController {

    private final TenantService service;

    public TenantWebController(TenantService service) {
        this.service = service;
    }


    /**
     * 创建企业
     * @param param
     * @return
     */
    @PostMapping("/createTenant")
    public ApiResult createTenant(@RequestBody @Valid CreateTenantParam param) {
        service.createTenant(param);
        return ApiResult.ok();
    }


    /**
     * 修改企业
     * @param param
     */
    @PutMapping("/editTenant")
    public ApiResult editTenant(@RequestBody @Valid EditTenantParam param) {
        service.editTenant(param);
        return ApiResult.ok();
    }

    /**
     * 移除企业
     * @param id
     */
    @DeleteMapping("/removeTenant")
    public ApiResult removeTenant(@RequestParam("id") Long id) {
        service.removeTenant(id);
        return ApiResult.ok();
    }

    /**
     * 启动/禁用企业
     * @param id
     */
    @GetMapping("/enabledTenant")
    public ApiResult enabledTenant(@RequestParam("id") Long id) {
        service.enabledTenant(id);
        return ApiResult.ok();
    }

    /**
     * 获取企业详情
     * @param id
     * @return
     */
    @GetMapping("/getTenant")
    public ApiResult<GetTenantVo> getTenant(@RequestParam("id") Long id) {
        GetTenantVo vo = service.getTenant(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取企业列表
     * @param param
     * @return
     */
    @PostMapping("/getTenantList")
    public ApiResult<PageResult<GetTenantListVo>> getTenantList(@RequestBody GetTenantListParam param) {
        PageResult<GetTenantListVo> result = service.getTenantList(param);
        return ApiResult.ok(result);
    }


    /**
     * 获取企业下拉列表
     *
     * @return
     */
    @PostMapping("/getTenantDownList")
    public ApiResult<List<GetTenantDownListVo>> getTenantDownList(@RequestBody(required = false) @Valid GetTenantDownListParam param) {
        List<GetTenantDownListVo> list = service.getTenantDownList(param);
        return ApiResult.ok(list);
    }

    /**
     * 部门树型
     * @param param
     * @return
     */
    @PostMapping("/tree")
    public ApiResult<List<TenantTreeVo>> getTenantTree(@RequestBody @Valid GetTenantTreeParam param) {
        List<TenantTreeVo> list = service.getTenantTree(param);
        return ApiResult.ok(list);
    }


}

